using UnityEngine;
namespace DefaultNamespace.FaceCustom
{
    /// <summary>
    /// 所有装备模型必须使用相同骨骼绑定方式（即来自同一个 Avatar）
    /// </summary>
    public class EquipmentManager:MonoBehaviour
    {
        public Transform boneRoot;
        public Transform equipmentSlot;
        
        public void Equip(GameObject equipmentPrefab)
        {
            GameObject newEquip = Instantiate(equipmentPrefab, equipmentSlot);
            var smr = newEquip.GetComponent<SkinnedMeshRenderer>();
            // 绑定骨骼
            smr.rootBone = boneRoot;
            //GetComponentInChildren<T>() 是 Unity 中非常常用的方法，用来从某个 GameObject（或其子对象）中查找第一个匹配的组件。
            smr.bones = GetComponentInChildren<SkinnedMeshRenderer>().bones;
            SkinnedMeshRenderer[] allRenderers = GetComponentsInChildren<SkinnedMeshRenderer>();
        }
    }
}